from rest_framework import serializers

from . import models

class CourseCategoryModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseCategory
        fields = ['id', 'name']


class TeacherModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Teacher
        fields = ['id', 'name', 'title', 'signature', 'brief', 'image']

# 课程列表页数据展示
class CourseModelSerialzier(serializers.ModelSerializer):

    teacher = TeacherModelSerializer()

    class Meta:
        model = models.Course
        fields = ['id', 'name', 'discount_name','real_price','course_img', 'students', 'lessons', 'pub_lessons', 'price', 'teacher', 'get_lessons']

# 课程详情数据
class CourseDetailModelSerializer(serializers.ModelSerializer):
    teacher = TeacherModelSerializer()
    class Meta:
        model = models.Course
        #  获取choice属性参数的值,可以直接使用get_属性名称_display
        fields = ['id', 'name', 'discount_name','activity_left_time','real_price','course_img', 'students' , 'lessons', 'join_brief', 'teacher','pub_lessons', 'price','level_name']



class LessonModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseLesson
        fields = ['id', 'name', 'section_link', 'duration', 'free_trail', 'lesson']


class ChapterModelSerializer(serializers.ModelSerializer):
    coursesections = LessonModelSerializer(many=True)

    class Meta:
        model = models.CourseChapter
        fields = ['id', 'chapter', 'name', 'coursesections']









